$(function() {
	var id = "";
	$('.btn-close').click(function(e) {
		e.preventDefault();
		$(this).parent().parent().parent().fadeOut();
	});
	$('.btn-add').click(function(e) {
		e.preventDefault();
		$('#addDiv').modal('show');
	});
	$('.btn-edit').click(function(e) {
		var checkBoxArray = $("input:checked");
		id = $("input:checked").val();
		if (checkBoxArray.length > 1) {
			failureTip("只能选择一条记录");
			return;
		}
		if (checkBoxArray.length < 1) {
			failureTip("请选择一条记录操作");
			return;
		}
		$.ajax({
			type : "post",
			data : {
				id : id
			},
			url : Globals.ctx + "${camelModelName}/select${modelName}ById",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : function(result) {
				var ${camelModelName} = result.retmsg;
				$("#${camelModelName}Id").val(${camelModelName}.id);
				<#list columnList as column>
					$("#${column}").val(${camelModelName}.${column});
				</#list>
			},
			complete : function(XMLHttpRequest, textStatus) {
			},
			error : function(data) {
			}
		});
		e.preventDefault();
		$('#editDiv').modal('show');
	});
	$('.btn-Del').click(function(e) {
		var checkBoxArray = $("input:checked");
		id = $("input:checked").val();
		if (checkBoxArray.length > 1) {
			failureTip("只能选择一条记录");
			return;
		}
		if (checkBoxArray.length < 1) {
			failureTip("请选择一条记录操作");
			return;
		}
		e.preventDefault();
		$('#delDiv').modal('show');
	});
	// 删除操作
	$("#delButton").click(function() {
		$.ajax({
			type : "post",
			data : {
				id : id
			},
			url : Globals.ctx + "${camelModelName}/delete",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : function(result) {
				if (result.retcode == 1) {
					successTip(result.retmsg);
				} else {
					failureTip(result.retmsg);
				}
				location.href = Globals.ctx + "${camelModelName}/${camelModelName}Info";
			},
			complete : function(XMLHttpRequest, textStatus) {
			},
			error : function(data) {
			}
		});
	});
});